home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / osrc.arc / LCSUM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-12  |  774 b   |  31 lines

  1. #if    (defined(MPU8086) || defined(MPU8080) || defined(vax))
  2. #define    LITTLE_ENDIAN    /* Low order bytes are first in memory */
  3. #endif            /* Almost all other machines are big-endian */
  4. #include "global.h"
  5.  
  6. int16 eac();
  7.  
  8. /*
  9.  * Word aligned linear buffer checksum routine.  Called from mbuf checksum
  10.  * routine with simple args.  Intent is that this routine may be replaced
  11.  * by assembly language routine for speed if so desired.
  12.  */
  13. int16
  14. lcsum(wp,len)
  15. register int16 *wp;
  16. register int16 len;
  17. {
  18.     register int32 sum = 0;
  19.     int16 result;
  20.  
  21.     while(len-- != 0)
  22.         sum += *wp++;
  23.     result = eac(sum);
  24. #ifdef    LITTLE_ENDIAN
  25.     /* Swap the result because of the (char *) to (int *) type punning */
  26.     result = (result << 8) | (result >> 8);
  27. #endif
  28.     return result;
  29. }
  30.  
  31.